﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;

namespace Billing.DataObjects
{
    public class UserRightsLoaderImp : IUserRightsLoader
    {
        #region IUserRightsLoader Members

        public void FillRightsFromDatabase(Object obj, UserRightsManager manager)
        {
            string fullName = obj.GetType().FullName;
            ISingleResult<GetRightPropertyStatusByFormResult> properties = new ShellDataContext().GetRightPropertyStatusByForm(Profile.UserGUID, obj.GetType().FullName);
            int propertiesCount = 0;

            foreach (GetRightPropertyStatusByFormResult propertyName in properties)
            {
                manager.AddObjectProperty(fullName, propertyName.Name);
                propertiesCount++;
            }
            if (propertiesCount == 0)
            {
                manager.AddObjectProperty(fullName, String.Empty);
            }
        }

        #endregion
    }
}
